 /***********************************************************
 *  File_Name  : XJUseTime.h
 *  File_Path   : 
 *  File_Encode : UTF8
 *  Description : 耗时统计
 *  
 *  OS : Linux, UNIX
 *  LastVersion  : 20130723
 *      
 *  Author      : LiXiujie(李秀杰)
 *  Date        : 2014-4-17
 *  Version     : 20130417
 *  Description :
 *                
 *  Edit Author : 
 *  Edit Date   : 
 *  Version     : 
 *  Description :
 *                
 ***********************************************************/
#include "XJDateTime.h"
#include <sys/time.h>  
#include <sys/timeb.h>
#include <string.h>
#include <time.h>
#include <stdio.h>

namespace XJUtilClass {
XJDateTime::XJDateTime() {
	// TODO Auto-generated constructor stub

}

XJDateTime::~XJDateTime() {
	// TODO Auto-generated destructor stub
}

void XJDateTime::GetLocalDate(char* szDate, unsigned long &nLen)
{
	time_t		tCurTime=time(NULL);
	struct tm*	ptmCurTime=localtime(&tCurTime);

	snprintf(szDate,nLen, "%04d%02d%02d",
		ptmCurTime->tm_year+1900,ptmCurTime->tm_mon+1,ptmCurTime->tm_mday);
}

void XJDateTime::GetLocalTime(char* szTime, unsigned long &nLen)
{
	time_t		tCurTime=time(NULL);
	struct tm*	ptmCurTime=localtime(&tCurTime);
	snprintf(szTime, nLen, "%02d%02d%02d",
		ptmCurTime->tm_hour,ptmCurTime->tm_min,ptmCurTime->tm_sec);
}

inline int64_t XJDateTime::GetCurrMilliTime()
{
	struct timeval tv;  
    gettimeofday(&tv, NULL);  
    // printf("Current time in milliseconds: %lld\n", milliseconds);  
	return tv.tv_sec * 1000LL + tv.tv_usec / 1000;  
}
//得到毫秒级系统时间
int64_t  XJDateTime::GetSystemMilliTime()
{
	struct timeb loTimeb;
	memset(&loTimeb, 0 , sizeof(timeb));
	ftime(&loTimeb); 
	return ((int64_t)loTimeb.time * 1000) + loTimeb.millitm;
}

} /* namespace XJUtilClass */
